package com.neidetcher.tuml;

import java.util.ArrayList;
import java.util.List;

import com.neidetcher.tuml.model.Message;
import com.neidetcher.tuml.model.Model;
import com.neidetcher.tuml.model.Object;

public class Parser
{
   public static Model parse(List<String> inputLines)
   {
      Model model = parseObjectDefinitionLine(inputLines.get(0));
      
      // for the rest of the parsing we need to go thru all the messages
      // and add those to the model, we could also add methods to the
      // objects
      model.setMessages(parseMessages(inputLines));
            
      return model;
   }
   
   private static Model parseObjectDefinitionLine(String headerLine)
   {
      Model model = new Model();

      List<Object> objects = new ArrayList<Object>();
      for(String currElement: headerLine.split(" "))
      {
         System.out.println("currElement: " + currElement);
         Object object = new Object(currElement);
         objects.add(object);
      }
      model.setObjects(objects);
      
      return model;
   }
   
   private static List<Message> parseMessages(List<String> inputLines)
   {
      List<Message> messages = new ArrayList<Message>();
      
      for(String currLine: inputLines.subList(1, inputLines.size()))
      {
         messages.add(new Message(currLine));
      }
      
      return messages;
   }
}
